package znbkChangeNote.presenter;

import com.example.lancooznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.lancooznbk.view.base.ILoadDataPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkChangeNote.api.DeleteNoteApi;
import znbkChangeNote.entity.DeleteNoteEntity;
import znbkTestPaperBj.ZnbkPaperBjInfor;
import znbkTestPaperBj.activity.NotePaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperInfor.ZnbkPaperInfor;
import znbkTopicType.NoteDetailActivity;

/**
 * Created by Administrator on 2018\3\19 0019.
 */

public class DeleteNotePresenter implements ILoadDataPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private DeleteNoteEntity DeleteNoteEntity;
    private boolean isFromExit = false;

    public DeleteNotePresenter(ILoadPaperView view,int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    public DeleteNotePresenter(ILoadPaperView view,int modelFrom,DeleteNoteEntity deleteNoteEntity) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
        this.DeleteNoteEntity =deleteNoteEntity;
    }

    @Override
    public void getData(boolean isShowLoading) {

        HttpOnNextListener<String> httpOnNextListener = new HttpOnNextListener<String>(){

            @Override
            public void onNext(String deleteNoteResult) {
                if(deleteNoteResult.equals("true")){

//                    if (isFromExit){
//                        ToastUtils.showShort("数据保存成功");
//                        new Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//
//                            }
//                        },600);

//                    }
                    ToastUtils.showShort("数据删除成功!");
                }else{
//                    ToastUtils.showShort("数据保存失败! 错误信息"+saveZsdEntityResult);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                //view.showNetError();
                ToastUtils.showShort("数据删除失败!");
            }
        };


        DeleteNoteApi api = null;
        if(ModelFrom == ZnbkPaperDef.FROM_NOTE) {
            api = new DeleteNoteApi(httpOnNextListener, (NotePaperActivity) view);
            DeleteNoteEntity deleteNoteEntity = new DeleteNoteEntity(UserInfo.StuId,UserInfo.SubjectId,
                    UserInfo.StageNo, ZnbkPaperBjInfor.NoteID,ZnbkPaperBjInfor.ResType,ZnbkPaperBjInfor.QuesID);
            api.setmDeleteNoteEntity(deleteNoteEntity);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING||
                ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION||
                ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION||
                ModelFrom==ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION_SPL||
                ModelFrom==ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION){
            api = new DeleteNoteApi(httpOnNextListener, (NoteDetailActivity) view);
            api.setmDeleteNoteEntity(DeleteNoteEntity);
        }

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}